package com.zhangqie.dnui;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.zhangqie.dnui.demo1.Demo1_1;
import com.zhangqie.dnui.demo1.Demo1_2;
import com.zhangqie.dnui.demo1.Demo1_3;
import com.zhangqie.dnui.demo1.Demo1_4;
import com.zhangqie.dnui.demo2.RecyclerViewActivity;

/***
 * 动脑高级UI
 */
public class MainActivity extends AppCompatActivity {


    private ListView listView;
    private String[] strings = new String[]{"UI1","UI-LinearLayoutCompat1","UI-LinearLayoutCompat2",
            "RecyclerView","RecyclerView2"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView(){
        listView = findViewById(R.id.listivew);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,strings);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                showIndex(position);
            }
        });
    }


    private void showIndex(int index){
        switch (index){
            case 0:
                startActivity(new Intent(MainActivity.this,Demo1_1.class));
                break;
            case 1:
                startActivity(new Intent(MainActivity.this,Demo1_2.class));
                break;
            case 2:
                startActivity(new Intent(MainActivity.this,Demo1_3.class));
                break;
            case 3:
                startActivity(new Intent(MainActivity.this,Demo1_4.class));
                break;
            case 4:
                startActivity(new Intent(MainActivity.this,RecyclerViewActivity.class));
                break;

        }
    }
}
